package com.yanfan.energy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yanfan.common.utils.StringUtils;
import com.yanfan.energy.domain.IbmsEnergyDevice;
import com.yanfan.energy.mapper.IbmsEnergyDeviceMapper;
import com.yanfan.energy.service.IIbmsEnergyDeviceService;
import com.yanfan.ibms.common.vo.DeviceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 能耗设备Service业务层处理
 *
 * @author genluo
 * @date 2024-09-18
 */
@Service
public class IbmsEnergyDeviceServiceImpl extends ServiceImpl<IbmsEnergyDeviceMapper, IbmsEnergyDevice> implements IIbmsEnergyDeviceService {
    @Autowired
    private IbmsEnergyDeviceMapper ibmsEnergyDeviceMapper;


    /**
     * 查询能耗设备列表
     *
     * @param ibmsEnergyDevice 能耗设备
     * @return 能耗设备
     */
    @Override
    public List<IbmsEnergyDevice> queryPageList(IbmsEnergyDevice ibmsEnergyDevice) {
       /* LambdaQueryWrapper<IbmsEnergyDevice> lqw = buildQueryWrapper(ibmsEnergyDevice);
        return ibmsEnergyDeviceMapper.selectList(lqw);*/
        //连表查询可用该方法，在此方法SQL语句上进行扩展
        return ibmsEnergyDeviceMapper.queryPageList(ibmsEnergyDevice);
    }

    @Override
    public List<DeviceVo> selectByDeviceType(String deviceType, String deptType) {

        List<DeviceVo>list = ibmsEnergyDeviceMapper.selectByDeviceType(deviceType,deptType);
        return list;
    }

    /**
     * 分页查询条件
     * @return
     */
    private LambdaQueryWrapper<IbmsEnergyDevice> buildQueryWrapper(IbmsEnergyDevice bo) {
        LambdaQueryWrapper<IbmsEnergyDevice> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(bo.getEnergyDeviceType()), IbmsEnergyDevice::getEnergyDeviceType, bo.getEnergyDeviceType());
        lqw.eq(StringUtils.isNotBlank(bo.getEnergyDeviceNumber()), IbmsEnergyDevice::getEnergyDeviceNumber, bo.getEnergyDeviceNumber());
        lqw.like(StringUtils.isNotBlank(bo.getEnergyDeviceName()), IbmsEnergyDevice::getEnergyDeviceName, bo.getEnergyDeviceName());
        lqw.eq(StringUtils.isNotBlank(bo.getEnergyDeviceAddress()), IbmsEnergyDevice::getEnergyDeviceAddress, bo.getEnergyDeviceAddress());
        lqw.eq(StringUtils.isNotBlank(bo.getEnergyDevicePosition()), IbmsEnergyDevice::getEnergyDevicePosition, bo.getEnergyDevicePosition());
        lqw.eq(bo.getCreatedAt() != null, IbmsEnergyDevice::getCreatedAt, bo.getCreatedAt());
        lqw.eq(bo.getUpdatedAt() != null, IbmsEnergyDevice::getUpdatedAt, bo.getUpdatedAt());
        lqw.eq(StringUtils.isNotBlank(bo.getIsBusiness()), IbmsEnergyDevice::getIsBusiness, bo.getIsBusiness());
        return lqw;
    }



}
